package com.qn.sms.service.impl;

import com.qn.sms.core.client.SmsClient;
import com.qn.sms.core.client.SmsClientFactory;
import com.qn.sms.core.client.dto.SmsSendRespDTO;
import com.qn.sms.core.client.vo.SmsCommonResult;
import com.qn.sms.core.enums.SmsChannelEnum;
import com.qn.sms.service.SmsChannelService;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Map;

@Service
public class SmsChannelServiceImpl implements SmsChannelService {

    @Resource
    private SmsClientFactory smsClientFactory;

    @PostConstruct
    public void initSmsClients() {
        // 创建或更新短信 Client
        smsClientFactory.createOrUpdateSmsClient(SmsChannelEnum.ALIYUN);
    }

    @Override
    public SmsCommonResult<SmsSendRespDTO> sendSingleSms(String mobile, String userId, String templateCode, Map<String, Object> templateParams) {
        SmsClient smsClient = smsClientFactory.getSmsClient(SmsChannelEnum.ALIYUN);
        return smsClient.sendSms(userId, mobile, templateCode, templateParams);
    }
}
